﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Web.UI;

namespace Altairis.Web.UI.WebControls {
    public class IconLinkButton : ImageButton {
        private const string ResourceNameFormat = "Altairis.Web.UI.Resources.Icons.{0}.png";

        [Category("Appearance"), Themeable(true), Bindable(true), DefaultValue(IconType.NoIcon)]
        public IconType Icon {
            get { return (IconType)(this.ViewState["Icon"] ?? IconType.NoIcon); }
            set {
                this.ViewState["Icon"] = value;
            }
        }

        [Browsable(false)]
        new private string ImageUrl {
            get {
                return this.Page.ClientScript.GetWebResourceUrl(
                    this.GetType(),
                    string.Format(ResourceNameFormat, this.Icon));
            }
            set {
                base.ImageUrl = this.Page.ClientScript.GetWebResourceUrl(
                    this.GetType(),
                    string.Format(ResourceNameFormat, this.Icon));
            }
        }

        [Browsable(false)]
        new private Unit Width {
            get {
                return Unit.Pixel(16); ;
            }
            set {
                base.Width = Unit.Pixel(16);
            }
        }

        [Browsable(false)]
        new private Unit Height {
            get {
                return Unit.Pixel(16);
            }
            set {
                base.Height = Unit.Pixel(16);
            }
        }

        protected override void OnPreRender(EventArgs e) {
            this.ImageUrl = this.Page.ClientScript.GetWebResourceUrl(
                            this.GetType(),
                            string.Format(ResourceNameFormat, this.Icon));
            base.OnPreRender(e);
        }

    }
}
